package com.wu.controller.system;


import com.wu.base.ApiResponse;
import com.wu.controller.BaseController;
import com.wu.pojo.reqeust.BaseRequest;
import com.wu.pojo.reqeust.CommonIdRequest;
import com.wu.pojo.reqeust.CommonIdStatusRequest;
import com.wu.pojo.reqeust.sys.DeletePositionRequest;
import com.wu.pojo.reqeust.sys.ListPositionRequest;
import com.wu.pojo.reqeust.sys.SavePositionRequest;
import com.wu.pojo.reqeust.sys.UpdatePositionRequest;
import com.wu.pojo.response.sys.PositionListResponse;
import com.wu.pojo.response.sys.PositionUserListResponse;
import com.wu.service.sys.SPositionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 职务表 前端控制器
 * </p>
 *
 * @author wujilu
 * @since 2020-11-24
 */
@RestController
@Api(tags = "S职务相关接口")
@RequestMapping("/position")
public class SPositionController extends BaseController {

    @Resource
    private SPositionService positionService;

    @ApiOperation(value = "职务 列表")
    @RequiresPermissions("/position/listPosition")
    @PostMapping(value = "/listPosition")
    public ApiResponse<PositionListResponse> listPosition(@RequestBody ListPositionRequest request) {
        return positionService.listPosition(request);
    }

    @ApiOperation(value = "下拉选择列表")
    @RequiresPermissions("/position/optionList")
    @PostMapping(value = "/optionList")
    public ApiResponse<PositionListResponse> optionList(@Validated() @RequestBody BaseRequest request) {
        return positionService.optionList(request);
    }

    @ApiOperation(value = "新增")
    @RequiresPermissions("/position/save")
    @PostMapping(value = "/save")
    public ApiResponse save(@Validated() @RequestBody SavePositionRequest request) {
        return positionService.save(request, getSessionUserId());
    }

    @ApiOperation(value = "修改")
    @RequiresPermissions("/position/edit")
    @PostMapping(value = "/edit")
    public ApiResponse edit(@Validated() @RequestBody UpdatePositionRequest request) {
        return positionService.edit(request, getSessionUserId());
    }

    /**
     * 删除 职务
     */
    @ApiOperation(value = "删除")
    @RequiresPermissions("/position/deletePosition")
    @PostMapping(value = "/deletePosition")
    public ApiResponse deletePosition(@Validated() @RequestBody DeletePositionRequest request) {
        return positionService.deletePosition(request, getSessionUserId());
    }

    @ApiOperation(value = "停用/启用")
    @RequiresPermissions("/position/onOrOff")
    @PostMapping(value = "/onOrOff")
    public ApiResponse onOrOff(@Validated() @RequestBody CommonIdStatusRequest request) {
        return positionService.onOrOff(request);
    }

    @ApiOperation(value = "根据id查询")
    @RequiresPermissions("/position/getById")
    @PostMapping(value = "/getById")
    public ApiResponse<PositionListResponse> getById(@Validated() @RequestBody CommonIdRequest request) {
        return positionService.getById(request);
    }

    @ApiOperation(value = "根据id查询职位下人员列表")
    @RequiresPermissions("/position/positionUserList")
    @PostMapping(value = "/positionUserList")
    public ApiResponse<PositionUserListResponse> positionUserList(@Validated() @RequestBody CommonIdRequest request) {
        return positionService.positionUserList(request);
    }


}
